package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPosts;
import com.ruoyi.system.service.ISysPostsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发布Controller
 * 
 * @author ruoyi
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/sypost/posts")
public class SysPostsController extends BaseController
{
    @Autowired
    private ISysPostsService sysPostsService;

    /**
     * 查询发布列表
     */
    @PreAuthorize("@ss.hasPermi('sypost:posts:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPosts sysPosts)
    {
        startPage();
        List<SysPosts> list = sysPostsService.selectSysPostsList(sysPosts);
        return getDataTable(list);
    }

    /**
     * 导出发布列表
     */
    @PreAuthorize("@ss.hasPermi('sypost:posts:export')")
    @Log(title = "发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPosts sysPosts)
    {
        List<SysPosts> list = sysPostsService.selectSysPostsList(sysPosts);
        ExcelUtil<SysPosts> util = new ExcelUtil<SysPosts>(SysPosts.class);
        util.exportExcel(response, list, "发布数据");
    }

    /**
     * 获取发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('sypost:posts:query')")
    @GetMapping(value = "/{postId}")
    public AjaxResult getInfo(@PathVariable("postId") Long postId)
    {
        return success(sysPostsService.selectSysPostsByPostId(postId));
    }

    /**
     * 新增发布
     */
    @PreAuthorize("@ss.hasPermi('sypost:posts:add')")
    @Log(title = "发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPosts sysPosts)
    {
        return toAjax(sysPostsService.insertSysPosts(sysPosts));
    }

    /**
     * 修改发布
     */
    @PreAuthorize("@ss.hasPermi('sypost:posts:edit')")
    @Log(title = "发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPosts sysPosts)
    {
        return toAjax(sysPostsService.updateSysPosts(sysPosts));
    }

    /**
     * 删除发布
     */
    @PreAuthorize("@ss.hasPermi('sypost:posts:remove')")
    @Log(title = "发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postIds}")
    public AjaxResult remove(@PathVariable Long[] postIds)
    {
        return toAjax(sysPostsService.deleteSysPostsByPostIds(postIds));
    }
}
